package com.euond.accv.mdm.api.controller;

import com.euond.accv.mdm.service.SystemCodeApiService;
import com.euond.common.web.controller.annotation.FeignRestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.HashMap;
import java.util.Map;


@FeignRestController
@RequestMapping("/feign_api/bas_system_code")
@Api(description="单据服务")
public class SystemCodeApiController {
	
	@Autowired
	SystemCodeApiService systemCodeApiService;
	
	@Autowired
	private DiscoveryClient discoveryClient;
	
	@ApiOperation(value="获取系统单据编号", notes="")
	@GetMapping("/getSheetIdCode")
	public String getSystemSheetid(@RequestParam(value="billtypeNo")String billtypeNo
			) throws Exception{
		String billNo="";
		billNo= systemCodeApiService.doGetSystemSheetid(billtypeNo);
		return billNo;
	}
	
	@ApiOperation(value="根据字段获取单据编号", notes="")
	@GetMapping("/getCodeRuleNo")
	public String getBillNoCodeRuleNo(@RequestParam(value="billtypeNo")String billtypeNo,
			@RequestParam(value="detail", required=false)String detail) throws Exception{
		String billNo="";
		billNo= systemCodeApiService.getBillNoCodeRuleNo(billtypeNo,detail);
		return billNo;
	}
	/**
	 * 批量申请单号
	 * @param billtypeNo
	 * @param detail
	 * @param countNo
	 * @return
	 * @throws Exception
	 */
	@GetMapping("/getBatchNo")
	@ApiOperation(value="批量申请", notes="")
	public Map<String,Object> getCodeNo(@RequestParam(value="billtypeNo")String billtypeNo,
			@RequestParam(value="detail", required=false)String detail,
			@RequestParam(value="countNo",defaultValue="0")Integer countNo) throws Exception{
		Map<String, Object> paramsMap = new HashMap<String, Object>();
		Map<String,Object>  batchNo = new HashMap<String,Object>();
		paramsMap.put("billtypeNo",billtypeNo);
		paramsMap.put("detail", (detail != null && !detail.isEmpty()) ? detail : "");
		paramsMap.put("countNo", countNo);
		batchNo = systemCodeApiService.doGetBatchBillNo(paramsMap);
		return batchNo;
	}
	
	  /**
	   * 本地服务实例的信息
	   * @return
	   */
    @RequestMapping(value = "/instance-info", method = RequestMethod.GET)
	public ServiceInstance shwoinfo(){
		ServiceInstance localServiceInstance = this.discoveryClient.getLocalServiceInstance();
	    return localServiceInstance;
	}
	  
    
}
